package LeetCode.leetcode429;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class Review1 {
    public List<List<Integer>> levelOrder(Node root) {
        List<List<Integer>> res = new ArrayList<>();
        Queue<Node> queue = new LinkedList<>();
        if (root == null) return res;
        queue.offer(root);
        while (!queue.isEmpty()){
            int size = queue.size();
            List<Integer> line = new ArrayList<>(size);
            for (int i = 0; i < size; i++) {
                Node cur = queue.poll();
                line.add(cur.val);
                for (int j = 0; j < cur.children.size(); j++) {
                    queue.offer(cur.children.get(j));
                }
            }
            res.add(line);
        }
        return res;
    }
}
